/*
 *  Copyright 2011 Alexey Andreev.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package org.xthl.wiki;

import java.util.List;
import org.nop.templating.Template;
import org.nop.util.Injected;
import org.xthl.core.AbstractFragment;
import org.xthl.core.UserProfileFragment;
import org.xthl.core.api.User;
import org.xthl.wiki.api.ArticleLogic;
import org.xthl.wiki.api.Revision;
import org.xthl.wiki.api.RevisionSearchCritery;
import org.xthl.wiki.view.UserRevisionsFragmentView;

/**
 *
 * @author Alexey Andreev
 */
public class UserRevisionsFragment extends AbstractFragment implements UserProfileFragment {
    private ArticleLogic logic;
    private User user;

    @Injected
    public UserRevisionsFragment(ArticleLogic logic) {
        this.logic = logic;
    }

    @Override
    public Template render() {
        RevisionSearchCritery critery = new RevisionSearchCritery();
        critery.setAuthorId(user.getId());
        critery.setLimit(10);
        List<Revision> revisions = logic.findRevisions(critery);
        return createView(UserRevisionsFragmentView.class)
                .setRevisions(revisions)
                .setAuthor(user);
    }

    @Override
    public void setUser(User user) {
        this.user = user;
    }
}
